package com.yaojiaxun.logisticsPlatformSystem.controller;

import com.yaojiaxun.logisticsPlatformSystem.entity.BuildInfo;
import com.yaojiaxun.logisticsPlatformSystem.service.BuildInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * @Auther: yjx_j
 * @Date: 2019/1/23 11:00
 * @Description:
 */
@Controller
public class BuildInfoController {

    @Autowired
    BuildInfoService buildInfoService;

    @RequestMapping("/build_manage")
    public String BuildInfoIndex(@RequestParam(defaultValue = "1") Integer page, Map<String, Object> map){
        map.put("pageDTO", buildInfoService.findPage(page));
        return "system/build/build_manage";
    }

    @RequestMapping("/build_detail")
    public String getDetail(@RequestParam("buildId") Long buildId, @RequestParam("page") Integer page, Map<String, Object> map){
        map.put("page", page);
        map.put("buildInfo", buildInfoService.findBuildInfoById(buildId));
        return "system/build/build_detail";
    }

    @RequestMapping("/build_update_after")
    public String updateBuildAfter(@RequestParam("page") Integer page, BuildInfo buildInfo){
        buildInfoService.updateBuildInfo(buildInfo);
        return "redirect:/build_manage?page="+page;
    }

    @RequestMapping("/buildDelete")
    public String deleteBuildByBuildId(@RequestParam("buildId") Long buildId, @RequestParam("page") Integer page){
        buildInfoService.deleteBuildInfoById(buildId);
        return "redirect:/build_manage?page="+page;
    }

    @RequestMapping("/buildAddBefore")
    public String addBuildBefore(){
        return "system/build/build_add";
    }

    @RequestMapping("/build_add_after")
    public String addBuildAfter(BuildInfo buildInfo){
        buildInfoService.addBuildInfo(buildInfo);
        return "redirect:/build_manage";
    }
}
